<?php
namespace Admin\Controller\Sys;
use Admin\Controller\SystemController;

class SysChannelController extends SystemController
{
	public $model = "SysChannel";
	public $not_allow_action = ["foreverdelete", "delete"];
	
	public function _filter(&$map)
	{
		$_search = search_map();
		$map = !empty($_search) ? array_merge($_search, $map) : $map;
		$map['type'] = 2;
	}
	
    public function _before_insert()
    {
        $this->checkValid();
    }

    public function _before_update()
    {
        $this->checkValid();
    }
	
	public function _after_insert()
	{
		S('channelCache',null);
		D($this->model)->createChannelList();
	}
	
	public function _after_update()
	{
		S('channelCache',null);
		D($this->model)->createChannelList();
	}

    public function checkValid()
    {
        if ($_POST['sharing_ratio'] < 0 || $_POST['sharing_ratio'] > 100)
        {
            $this->error("渠道分成输入无效！请填写0-100之间(包含0和100)的数字！");
        }
    }
}
